﻿Public Class M9arir
    Public Id As Integer
    Public Nom As String
    Public Date_ta3yin As String
    Public Remarque As String
    Public actif As String

    'Les constructeur --------------------------


    Sub New(ByVal Id As Integer, ByVal Nom As String, ByVal Date_ta3yin As String, ByVal Remarque As String, ByVal actif As String)
        Me.Id = Id
        Me.Nom = Nom
        Me.Date_ta3yin = Date_ta3yin
        Me.Remarque = Remarque
        Me.actif = actif
    End Sub


    Sub New()

    End Sub

    'les listes ---------------------------------

    Public list_phone As ArrayList






    'les fonctions ---------------------------


    Public Sub remplir_List_list_phone()
        Me.list_phone.Clear()
        Dim cmd As New SqlClient.SqlCommand("select * from phone where id_Mo9arir" & Me.Id, Partager.con)
        Partager.Open()
        Partager.dr = cmd.ExecuteReader
        While Partager.dr.Read
           
            Dim khab As New Phone(Partager.dr("id"), Partager.dr("Num"), Partager.dr("Type"))
            Me.list_phone.Add(khab)
        End While
        Partager.Close()
    End Sub

    Public Sub suprimmer_phone(ByVal id As Integer)

        Dim cmd As New SqlClient.SqlCommand("delete from phone where id=" & id, Partager.con)

        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_List_list_phone()


    End Sub

    Public Sub Ajouter_phone(ByVal ph As Phone)

        Dim cmd As New SqlClient.SqlCommand("insert into phone(Num,Type,Id_Mo9arir) values (@Num,@Type,@Id_Mo9arir)", Partager.con)

        cmd.Parameters.Add("@Id_Mo9arir", SqlDbType.VarChar).Value = Me.Id
        cmd.Parameters.Add("@Type", SqlDbType.VarChar).Value = ph.Type
        cmd.Parameters.Add("@Num", SqlDbType.VarChar).Value = ph.Num


        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_List_list_phone()


    End Sub

    Public Sub modifier_List_phone(ByVal idd As Integer, ByVal ph As Phone)



        Dim cmd As New SqlClient.SqlCommand("update phone set  Num=@Num where id" & Id, Partager.con)


        cmd.Parameters.Add("@Num", SqlDbType.VarChar).Value = ph.Num

        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_List_list_phone()

    End Sub


End Class
